﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;

using zijian666.Abstractions;

namespace zijian666.Translator;

/// <summary>
/// 操作可循环对象的翻译器
/// </summary>
public class EnumeratorTranslator : ITranslator
{
    /// <inheritdoc />
    public bool TryTranslate(IConvertContext context, object? input, out object? translated)
    {
        translated = input switch
        {
            string => null,
            DataRow dataRow => dataRow.ItemArray,
            DataRowView dataRowView => dataRowView.Row?.ItemArray,
            DataTable dataTable => dataTable.Rows,
            DataSet dataSet => dataSet.Tables,
            IListSource listSource => listSource.GetList(),
            _ => null,
        };
        return translated != null;
    }
}
